//
//  PPImageShowVIew.m
//  PetParadise
//
//  Created by 陈无忌 on 8/3/14.
//  Copyright (c) 2014 whalefin. All rights reserved.
//

#import "PPImageShowVIew.h"
#import "supportingHeadFiles.h"
#import "PPTopicImage.h"

@implementation PPImageShowView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

+(PPImageShowView *)imageShowViewsetImagePositionWithImage:(NSArray <Optional,PPTopicImage>*)imageArray andView:(PPImageShowView *)view
{
    for (UIImageView *subView in view.subviews)
    {
        [subView removeFromSuperview];
    }
    view.frame = CGRectMake(84, 10, 76, 76);
    int count = imageArray.count;
    NSMutableArray *pathArray = [[NSMutableArray alloc] init];
    if (count > 0) {
        for (PPTopicImage *img in imageArray) {
            if (!img.img) {
                img.img = @"";
            }
            [pathArray addObject:img.img];
            
        }
    }
    
    if (count == 0) {
        view.hidden = YES;
    }else if (count == 1){
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(1, 1, 74, 74)];
        [imageView setImageWithURL:[PPImageUrl getImageUrl:[pathArray objectAtIndex:0]] placeholderImage:[UIImage imageNamed:@"defaultImage"] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        [imageView setContentMode:UIViewContentModeScaleAspectFill];
        [imageView setClipsToBounds:YES];

        [view addSubview:imageView];
    }else if(count == 2){
        for (int i = 0; i < count; i++) {
            UIImageView *imageView = [[UIImageView alloc] init];
            switch (i) {
                case 0:
                    imageView.frame = CGRectMake(1, 1, 36, 74);
                    break;
                case 1:
                    imageView.frame = CGRectMake(39, 1, 36, 74);
                    break;
                default:
                    break;
            }
            [imageView setImageWithURL:[PPImageUrl getImageUrl:[pathArray objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@"defaultImage"] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
            [imageView setContentMode:UIViewContentModeScaleAspectFill];
            [imageView setClipsToBounds:YES];
            
            [view addSubview:imageView];
        }
    }else if (count == 3){
        for (int i = 0; i < count; i++) {
            UIImageView *imageView = [[UIImageView alloc] init];
            switch (i) {
                case 0:
                    imageView.frame = CGRectMake(1, 1, 36, 74);
                    break;
                case 1:
                    imageView.frame = CGRectMake(39, 1, 36, 36);
                    break;
                case 2:
                    imageView.frame = CGRectMake(39, 39, 36, 36);
                    break;
                default:
                    break;
            }
            [imageView setImageWithURL:[PPImageUrl getImageUrl:[pathArray objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@"defaultImage"] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
            [imageView setContentMode:UIViewContentModeScaleAspectFill];
            [imageView setClipsToBounds:YES];
            
            [view addSubview:imageView];
        }
    }else{
        for (int i = 0; i < 4; i++) {
            UIImageView *imageView = [[UIImageView alloc] init];
            switch (i) {
                case 0:
                    imageView.frame = CGRectMake(1, 1, 36, 36);
                    break;
                case 1:
                    imageView.frame = CGRectMake(39, 1, 36, 36);
                    break;
                case 2:
                    imageView.frame = CGRectMake(1, 39, 36, 36);
                    break;
                case 3:
                    imageView.frame = CGRectMake(39, 39, 36, 36);
                    break;
                default:
                    break;
            }
            [imageView setImageWithURL:[PPImageUrl getImageUrl:[pathArray objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@"defaultImage"] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
            [imageView setContentMode:UIViewContentModeScaleAspectFill];
            [imageView setClipsToBounds:YES];
            
            [view addSubview:imageView];
        }
    }
    return view;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
